#include "stdio.h"
#include "stdlib.h"
typedef struct DNode
{
    int date;
    struct DNode *prior,*next;
}DNode,*DLinkList;
/*尾插法*/
void DList_TailInsert(DLinkList &L){
    printf("TailInsert:");
    int x;
    L=(DLinkList)malloc(sizeof(DNode));
    L->prior=NULL;L->next=NULL;
    DNode *s,*r=L;
    scanf("%d",&x);
    while (x!=EOF)
    {
        s=(DLinkList)malloc(sizeof(DNode));
        s->date=x;
        s->next=NULL;
        r->next=s;
        s->prior=r;
        r=s;
        scanf("%d",&x);
    }
}
/*查找第i个节点*/
DLinkList GetElem(DLinkList &L,int i){
    
    DNode *p=L->next;
    for(int j=1;p&&j<i;j++){
        p=p->next;
    }
    return p;
}
/*节点s插入第i位*/
void InsertNode(DLinkList &L,int i,int e){
    DNode *p=GetElem(L,i-1);
    DNode *s=(DLinkList)malloc(sizeof(DNode));
    s->date=e;
    s->next=p->next;
    p->next->prior=s;
    p->next=s;
    s->prior=p;
}
void DeleteNode(DLinkList &L,int i){
    DNode *p=GetElem(L,i);
    p->prior->next=p->next;
    p->next->prior=p->prior;
    free(p);
}
/*打印链表*/
void display(DLinkList &L){
    DNode *p;
    p=L->next;
    while (p!=NULL)
    {
        printf("%d ",p->date);
        p=p->next;
    }
    printf("end...\n");
}
int main()
{
    DNode *head;
    DList_TailInsert(head);
    display(head);
    printf("%d\n",GetElem(head,3)->prior->date);
    InsertNode(head,3,0);
    display(head);
    DeleteNode(head,3);
    display(head);
}